<template>
	<el-drawer :title="titleMap[mode]" v-model="visible" :size="600" append-to-body destroy-on-close @closed="$emit('closed')">
		<el-container>
			<el-main class="nopadding">
				<el-scrollbar>
					<el-row class="drawer-table">
						<el-col :span="24">
							<el-form :model="form" :rules="rules" :disabled="mode==='show'" ref="dialogForm" label-width="80px">
								<el-form-item label="收货地址" prop="hyUserAddressId">
									<el-input v-model="form.hyUserAddressId" placeholder="请输入收货地址" clearable></el-input>
								</el-form-item>
								<el-form-item label="会员id" prop="hyUserId">
									<el-input v-model="form.hyUserId" placeholder="请输入会员id" clearable></el-input>
								</el-form-item>
								<el-form-item label="公司名" prop="copName">
									<el-input v-model="form.copName" placeholder="请输入公司名" clearable></el-input>
								</el-form-item>
								<el-form-item label="联系人" prop="linkUserName">
									<el-input v-model="form.linkUserName" placeholder="请输入联系人" clearable></el-input>
								</el-form-item>
								<el-form-item label="电话" prop="tel">
									<el-input v-model="form.tel" placeholder="请输入电话" clearable></el-input>
								</el-form-item>
								<el-form-item label="微信" prop="wxCode">
									<el-input v-model="form.wxCode" placeholder="请输入微信" clearable></el-input>
								</el-form-item>
								<el-form-item label="区域" prop="regionPath">
									<el-input v-model="form.regionPath" placeholder="请输入区域" clearable></el-input>
								</el-form-item>
								<el-form-item label="定位地址" prop="district">
									<el-input v-model="form.district" placeholder="请输入定位地址" clearable></el-input>
								</el-form-item>
								<el-form-item label="详细地址 门牌号" prop="address">
									<el-input v-model="form.address" placeholder="请输入详细地址 门牌号" clearable></el-input>
								</el-form-item>
								<el-form-item label="邮编" prop="zipCode">
									<el-input v-model="form.zipCode" placeholder="请输入邮编" clearable></el-input>
								</el-form-item>
								<el-form-item label="是否默认" prop="isDef">
									<el-input v-model="form.isDef" placeholder="请输入是否默认" clearable></el-input>
								</el-form-item>
								<el-form-item label="备注" prop="msg">
									<el-input v-model="form.msg" placeholder="请输入备注" clearable></el-input>
								</el-form-item>
								<el-form-item label="0 1" prop="state">
									<el-input v-model="form.state" placeholder="请输入0 1" clearable></el-input>
								</el-form-item>
								<el-form-item label="跟踪人id" prop="ghSysUserId">
									<el-input v-model="form.ghSysUserId" placeholder="请输入跟踪人id" clearable></el-input>
								</el-form-item>
								<el-form-item label="经度" prop="longitude">
									<el-input v-model="form.longitude" placeholder="请输入经度" clearable></el-input>
								</el-form-item>
								<el-form-item label="纬度" prop="latitude">
									<el-input v-model="form.latitude" placeholder="请输入纬度" clearable></el-input>
								</el-form-item>
                            </el-form>
						</el-col>
					</el-row>
				</el-scrollbar>
			</el-main>
			<el-footer>
				<el-button v-if="mode!=='show'" :loading="isSaveing" @click="submit()" type="primary" size="small">保 存</el-button>
				<el-button size="small" @click="visible=false">取 消</el-button>
			</el-footer>
		</el-container>
	</el-drawer>
</template>
<script>
	export default {
		emits: ['success', 'closed'],
		data() {
			return {
				mode: "add",
				titleMap: {
					add: '新增',
					edit: '编辑',
					mode: '地址库'
				},
				visible: false,
				isSaveing: false,
				//表单数据
				form: {
					hyUserAddressId: "",
					hyUserId: "",
					copName: "",
					linkUserName: "",
					tel: "",
					wxCode: "",
					regionPath: "",
					district: "",
					address: "",
					zipCode: "",
					isDef: "",
					msg: "",
					state: "",
					ghSysUserId: "",
					longitude: "",
					latitude: "",
				},
				//验证规则
				rules: {
					userName: [
						{required: true, message: '请输入名称'}
					],
					userAge: [
						{pattern: /^[0-9]*$/, message: '年龄需为数字', trigger: 'blur'}
					],
					price: [
						{pattern: /^\d+(\.\d+)?$/, message: '价格需为数字', trigger: 'blur'}
					]
				}
			}
		},
		mounted() {

		},
		methods: {
			//显示
			open(mode='add'){
				this.mode = mode;
				this.visible = true;
				return this;
			},
			//表单提交方法
			submit(){
				this.$refs.dialogForm.validate(async (valid) => {
					if(valid){
						this.isSaveing = true;
						var res = await this.$API.hygl.hyUserAddress.save.post(this.form);
						this.isSaveing = false;
						if(res.code === 2000){
							this.$emit('success', this.form, this.mode);
							this.visible = false;
							this.$message.success(res.message);
						}else{
							this.$alert(res.message, "提示", {type: 'error'})
						}
					}
				});
			},
			//表单注入数据
			setData(data){
				this.form.hyUserAddressId = data.hyUserAddressId;
				this.form.hyUserId = data.hyUserId;
				this.form.copName = data.copName;
				this.form.linkUserName = data.linkUserName;
				this.form.tel = data.tel;
				this.form.wxCode = data.wxCode;
				this.form.regionPath = data.regionPath;
				this.form.district = data.district;
				this.form.address = data.address;
				this.form.zipCode = data.zipCode;
				this.form.isDef = data.isDef;
				this.form.msg = data.msg;
				this.form.state = data.state;
				this.form.ghSysUserId = data.ghSysUserId;
				this.form.longitude = data.longitude;
				this.form.latitude = data.latitude;
			}
		}
	}
</script>
<style>
</style>
